package com.signway.javaui.slice;

import com.signway.javaui.ResourceTable;
import com.signway.javaui.base.BaseAbilitySlice;
import com.signway.javaui.define.CommonData;
import com.signway.javaui.utils.SwToast;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;

public class MainAbilitySlice extends BaseAbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
    }

    private void initView() {
        /* 组件 */
        Button btnComponent = (Button) findComponentById(ResourceTable.Id_component);
        /* 布局 */
        Button btnLayout = (Button) findComponentById(ResourceTable.Id_layout);
        /* 弹框 */
        Button btnDialog = (Button) findComponentById(ResourceTable.Id_dialog);
        /* 列表 */
        Button btnContainer = (Button) findComponentById(ResourceTable.Id_container);
        /* Tab多页签 */
        Button btnTabPages = (Button) findComponentById(ResourceTable.Id_tab_pages);
        /* 新拟态风格 */
        Button btnNewMimicry = (Button) findComponentById(ResourceTable.Id_new_mimicry_style);

        btnComponent.setClickedListener(component -> {startAbility(CommonData.COMPONENT_ABILITY);});
        btnLayout.setClickedListener(component -> {startAbility(CommonData.LAYOUT_ABILITY);});
        btnDialog.setClickedListener(component -> {startAbility(CommonData.DIALOG_ABILITY);});
        btnContainer.setClickedListener(component -> {startAbility(CommonData.CONTAINER_ABILITY);});
        btnTabPages.setClickedListener(component -> {startAbility(CommonData.TAB_PAGES_ABILITY);});
        btnNewMimicry.setClickedListener(component -> {startAbility(CommonData.NEW_MIMICRY_ABILITY);});
    }

    private void startAbility(String abilityName) {
        if (abilityName.isEmpty()) {
            SwToast.showToast(this, "开发中...");
            return;
        }
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(getBundleName())
                .withAbilityName(abilityName)
                .build();
        intent.setOperation(operation);
        startAbility(intent);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
